package wrapper;

import org.junit.jupiter.api.Test;


/**
 * @Author Mr.Wen
 * @Version 1.0
 */
public class Test2 {
    @Test
    void test() {
//        TODO String常量池问题
        String s = new String("hang");
        String s2 = s.intern();/*直接返回常量池中的hang*/
        String s3 = s;/*指向堆中s地址*/
        System.out.println(s2 == s);/*false*/
        System.out.println(s == s3);/*true*/
    }

    @Test
    void test2() {
        String str = new String("he") + new String("llo");
        String s = str.intern();
        System.out.println(s == str);
    }

    @Test
    void test3() {
        String s1 = "ha";
        String s2 = "ng";
        String s3 = "ha" + "ng";
        System.out.println(s1 == s2);
        System.out.println(s2 == s3);
    }

    @Test
    void test4() {
        String s1 = "ha";
        String s2 = "ng";
        String s3 = "ha" + "ng";/*不创建对象*/
        String s4 = s1 + s2;/*创建对象*/
        System.out.println(s3 == s4.intern());
    }

    @Test
    void test5() {
        String s3 = new String("软件") + new String("工程");
        System.out.println(s3 == s3.intern());

        String s4 = new String("ja") + new String("va");
        System.out.println(s4 == s4.intern());
    }

    @Test
    void test6() {
        System.out.println(Runtime.getRuntime().availableProcessors());

    }
}
